const app = getApp()
const WxParse = require('../../wxParse/wxParse.js');
const Util = require('../../utils/util.js');
const Api = require('../../api/api.js')

Page({
  data: {
    // 轮播数据
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    indicatorColor: "#ccc",
    indicatorActiveColor: "#f66",
    // 页面数据
    id: '',
    click: '',
    addr: '',
    price: '',
    tel: '',
    className: '',
    imgUrl: '',
    summary: '',
    mytag: '',
    sys_code: '',
    ticketList: [],
    ticketTags: ["节假日开放", "周末开放", "支持退款"],
    // 弹框
    other_show: true,
    scenicContent :''
  },
  onLoad: function (params) {
    this.setData({
      id: params.id
    })

    wx.showToast({
      title: '加载中',
      icon: 'loading',

    })
    var that = this;

    Api.getScenicDetail({
      data: app.addParams({
        scenicId: that.data.id
      }),
      success:(res) => {
        console.log('++++++++++++++++订单详情数据++++++++++++++++')
        console.log(res)
        that.setData({
          name: res.data.data.scenic.name,
          addr: res.data.data.scenic.addr,
          tel: res.data.data.scenic.tel,
          className: res.data.data.scenic.className,
          price: res.data.data.scenic.price,
          imgUrl: res.data.data.scenic.imgUrl,
          summary: res.data.data.scenic.summary,
          ticketList: res.data.data.ticketList,
          scenicContent: res.data.data.scenicContent
        })
      }
    })
  },


  //事件处理函数
  bindViewTap: function (event) {
    that.setData({
      click: event.target.dataset.click
    })
  },
  // 打开地图
  openMap: function (e) {
    let that = this;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度  
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          name: that.data.addr,
          scale: 28
        })
      }
    })
  },
  // 拨打电话
  callPhone: function () {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: this.data.tel, //此号码并非真实电话号码，仅用于测试
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  //关闭富文本弹框
  cancelText: function () {
    this.setData({
      other_show: true
    })
  },
  // 打开富文本弹框
  openMaskContent: function (e) {
    // let _name = e.currentTarget.dataset.name,
    //   _text,
    //   that = this;
    // switch (_name) {
    //   case 'scenicContent': //景区介绍
    //     _text = that.data.scenicContent;
    //     break;
    //   case 'scenicNotice':  //预订须知
    //     _text = that.data.scenicNotice;
    //     break;
    //   case 'scenicDetail':
    //     let index = Number(e.currentTarget.dataset.index);
    //     _text = that.data.ticketList[index].name;
    //   default:
    //     break;
    // }
    // WxParse.wxParse('content', 'html', _text, that, 5);
    let that = this;
    WxParse.wxParse('content', 'html', that.data.scenicContent, that, 5);
    that.setData({
      other_show: false,
    })
  }

})
